package com.hamizhong.iflowers.web.action.admin.prodgoods;

import java.util.List;

import com.hamizhong.iflowers.service.IFestivalService;
import com.hamizhong.iflowers.service.IFlowerCountService;
import com.hamizhong.iflowers.service.IFlowerFloridService;
import com.hamizhong.iflowers.service.IGoodsService;
import com.hamizhong.iflowers.service.IProductService;
import com.hamizhong.iflowers.service.IPurposeService;
import com.hamizhong.iflowers.service.ITargetService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.web.base.MyBaseAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.GoodsVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;
import com.hamizhong.iflowers.web.vo.PurposeVO;

public class GoodsUpdateAction extends MyBaseAction {
	private IGoodsService iGoodsService = null;
	private IProductService iProductService = null;
	private IPurposeService iPurposeService = null;
	private IFestivalService iFestivalService = null;
	private ITargetService iTargetService = null;
	private IFlowerFloridService iFlowerFloridService = null;
	private IFlowerCountService iFlowerCountService = null;
	
	public IGoodsService getiGoodsService() {
		return iGoodsService;
	}
	public void setiGoodsService(IGoodsService iGoodsService) {
		this.iGoodsService = iGoodsService;
	}
	public IProductService getiProductService() {
		return iProductService;
	}
	public void setiProductService(IProductService iProductService) {
		this.iProductService = iProductService;
	}
	public IPurposeService getiPurposeService() {
		return iPurposeService;
	}
	public void setiPurposeService(IPurposeService iPurposeService) {
		this.iPurposeService = iPurposeService;
	}
	public IFestivalService getiFestivalService() {
		return iFestivalService;
	}
	public void setiFestivalService(IFestivalService iFestivalService) {
		this.iFestivalService = iFestivalService;
	}
	public ITargetService getiTargetService() {
		return iTargetService;
	}
	public void setiTargetService(ITargetService iTargetService) {
		this.iTargetService = iTargetService;
	}
	public IFlowerFloridService getiFlowerFloridService() {
		return iFlowerFloridService;
	}
	public void setiFlowerFloridService(IFlowerFloridService iFlowerFloridService) {
		this.iFlowerFloridService = iFlowerFloridService;
	}
	public IFlowerCountService getiFlowerCountService() {
		return iFlowerCountService;
	}
	public void setiFlowerCountService(IFlowerCountService iFlowerCountService) {
		this.iFlowerCountService = iFlowerCountService;
	}
	
	@Override
	protected String doRequest() {
		logger.info("----------------- Hello GoodsUpdateAction -----------------");
		String goodsId = getRQ().getParameter("goodsId");
		IOPResultDto<IObjectVO> resultDtoGoods = iGoodsService.findById(Integer.valueOf(goodsId));
		IOPResultDto<IObjectVO> resultDtoPurpose = iPurposeService.findAll(1, MyConstants.SIZE_OF_COMMON_FINDALL);
		IOPResultDto<IObjectVO> resultDtoFestival = iFestivalService.findAll(1, MyConstants.SIZE_OF_COMMON_FINDALL);
		IOPResultDto<IObjectVO> resultDtoTarget = iTargetService.findAll(1, MyConstants.SIZE_OF_COMMON_FINDALL);
		IOPResultDto<IObjectVO> resultDtoFlowerFlorid = iFlowerFloridService.findAll(1, MyConstants.SIZE_OF_COMMON_FINDALL);
		IOPResultDto<IObjectVO> resultDtoFlowerCount = iFlowerCountService.findAll(1, MyConstants.SIZE_OF_COMMON_FINDALL);
		if(resultDtoGoods.isSuccess()) {
			List<GoodsVO> goodsVOList = resultDtoGoods.getFirstResult().getGoodsVOList();
			GoodsVO goodsVO = goodsVOList.get(0);
			getRQ().setAttribute("goodsVO", goodsVO);
			getRQ().setAttribute("purposeVOList", resultDtoPurpose.getFirstResult().getPurposeVOList());
			getRQ().setAttribute("festivalVOList", resultDtoFestival.getFirstResult().getFestivalVOList());
			getRQ().setAttribute("targetVOList", resultDtoTarget.getFirstResult().getTargetVOList());
			getRQ().setAttribute("flowerFloridVOList", resultDtoFlowerFlorid.getFirstResult().getFlowerFloridVOList());
			getRQ().setAttribute("flowerCountVOList", resultDtoFlowerCount.getFirstResult().getFlowerCountVOList());
			return SUCCESS;
		}else {
			return ERROR;
		}
	}

}
